package org.edu.modules.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.StatementType;
import org.edu.modules.system.entity.ProcessInstance;
import org.edu.modules.system.entity.ProcessType;

import java.util.List;
import java.util.Map;

/**
 * @Author lbh
 * @Date 2025/2/13 上午9:10
 * @Version 1.0
 */
public interface ProcessInstanceMapper extends BaseMapper<ProcessInstance> {

    String currentStatus = "current_status";

    /**审批*/
    @Options(statementType = StatementType.CALLABLE)
    void approveProcess(@Param("instanceId") Integer instanceId,
                         @Param("approverId") String approverId,
                         @Param("approvalResult") String approvalResult,
                         @Param("comment") String comment);

    /**审批不通过重新提交*/
    @Options(statementType = StatementType.CALLABLE)
    void resubmitProcess(@Param("instanceId") Integer instanceId,
                        @Param("applicantId") String applicantId,
                        @Param("formData") String formData);

    /**发起流程*/
    @Options(statementType = StatementType.CALLABLE)
    void createProcess( @Param("processTypeId") Integer processTypeId,
                       @Param("applicantId") String applicantId,
                         @Param("formData") String formData);

    /**查看流程实例*/
    @Options(statementType = StatementType.CALLABLE)
    Map getProcessInstance(@Param("instanceId") Integer instanceId);
    /**待办计数*/
    @Options(statementType = StatementType.CALLABLE)
    Integer countDblc(@Param("userId") String userId);
    /**已办计数*/
    @Options(statementType = StatementType.CALLABLE)
    Integer countYblc(@Param("userId") String userId);
    /**待办列表*/
    @Options(statementType = StatementType.CALLABLE)
    IPage<ProcessInstance> spGetDblcPage(Page pageEntity,@Param("userId") String userId
            ,@Param("page") Long page,@Param("pageSize") Long pageSize);
    /**已办列表*/
    @Options(statementType = StatementType.CALLABLE)
    IPage<ProcessInstance> spGetYblcPage(Page pageEntity,@Param("userId") String userId
            ,@Param("page") Long page,@Param("pageSize") Long pageSize);

    // 查询我的待审批列表
//    Page<ProcessInstance> getMyApprovals(Page page, @Param("processInstance") ProcessInstance processInstance, @Param("userId") String userId);
    @Options(statementType = StatementType.CALLABLE)
    List<ProcessInstance> getMyApprovalsList(@Param("paramJson") String paramJson, @Param("approveId") String approveId);

    @Options(statementType = StatementType.CALLABLE)
    IPage<ProcessInstance> getMyApprovalsPage(Page pageEntity,@Param("paramJson") String paramJson, @Param("approveId") String approveId
    ,@Param("page") Long page,@Param("pageSize") Long pageSize);

    @Options(statementType = StatementType.CALLABLE)
    Long countMyApprovals(@Param("paramJson") String paramJson, @Param("approveId") String approveId);

    /**我发起的流程*/
    @Options(statementType = StatementType.CALLABLE)
    IPage<ProcessInstance> getMyCreateInstancePage(Page pageEntity,@Param("paramJson") String paramJson
            ,@Param("page") Long page,@Param("pageSize") Long pageSize);
    /**我发起的流程计数*/
    @Options(statementType = StatementType.CALLABLE)
    Long countMyCreateInstance(@Param("userId") String userId,@Param("paramJson") String paramJson);

    List<Map> countGroupByTypeId();

    @Options(statementType = StatementType.CALLABLE)
    int getLastInsertId();
}
